

#include <IRremote.h>

int RECV_PIN =7;
int LIGHT_PIN=11;
char bt_command;  
int studyRemote=0;

IRrecv irrecv(RECV_PIN);

decode_results results;

void dump(decode_results *results) {
 Serial.print("<msg>");
  int count = results->rawlen;
    Serial.print("<protocolType>");
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding");
  } 
  else if (results->decode_type == NEC) {
    Serial.print("NEC");
  } 
  else if (results->decode_type == SONY) {
    Serial.print("SONY");
  } 
  else if (results->decode_type == RC5) {
    Serial.print("RC5");
  } 
  else if (results->decode_type == RC6) {
    Serial.print("RC6");
  }
  else if (results->decode_type == PANASONIC) {	
    Serial.print("PANASONIC - Address: ");
    Serial.print(results->panasonicAddress,HEX);
    Serial.print(" Value: ");
  }
  else if (results->decode_type == JVC) {
     Serial.print("JVC:");
  }
  Serial.print("<protocolType>");
  Serial.print("<protocolTypeValue>");
  Serial.print(results->value, HEX);
   Serial.print("</protocolTypeValue>");
    Serial.print("<bits>");
  Serial.print(results->bits, DEC);
  Serial.print("</bits>");
  Serial.print("<Raw>");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 0; i < count; i++) {
    if ((i % 2) == 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    } 
    else {
      Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println("");
   Serial.print("</Raw>");
   Serial.print("</msg>");
}


void setup()
{
  Serial.begin(9600);
  //PIN 11
  pinMode(LIGHT_PIN,OUTPUT);  
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  
   bt_command = Serial.read();         
   if(bt_command=='1'){
       digitalWrite(LIGHT_PIN,HIGH);  
      Serial.println(bt_command);
   }
   if(bt_command=='0'){
        digitalWrite(LIGHT_PIN,LOW);  
        Serial.println(bt_command);
   }
   if(bt_command=='study'){
         studyRemote=1;
   }
   
   if(bt_command=='send'){
   
   }
   
  if (irrecv.decode(&results)) {
     dump(&results);
    irrecv.resume(); 
  }

}
